import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.*;
import java.util.*;

/**
 * Klasa ta pozwala na laczenie sie klienta(ClientClock)
 * ze zdalnym serwerem(ServerClock) i uzyskiwanie sformatowanej godziny.
 * @author KRZYSIEK
 *
 */
public class ClientClock extends Thread
{
	String sGet = "GET";
	String sOut = "BYE";
	String time;
	InputStream inStream;
	OutputStream outStream;
	Scanner in;
	PrintWriter out;
	
	public ClientClock()
	{
		

	}
	
	public void run()
	{
		try
		{
			Socket s = new Socket("127.0.0.1", 8189);
			try
			{
				
				inStream = s.getInputStream();
				outStream = s.getOutputStream();
				
				in = new Scanner(inStream);
				out = new PrintWriter(outStream, true /* autoFlush*/);
				
				//out.println("GET");
				out.println("GET");
				
				//pobieramy godzine z serwera co 1 s
				while(in.hasNextLine())
				{
					out.println("GET");
					time = in.nextLine();
					//System.out.println(line);
				}
				
			}
			finally
			{
				s.close();
			}
		}
		catch(IOException e)
		{
			//e.printStackTrace();
			time = "ERROR";
		}
	}
	

	
	public synchronized String getTime()
	{
		return this.time;
	}
	

}
